home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Essential Home & Business Collection
/
The Essential Home & Business Collection.iso
/
27
/
3
/
5
/
HP22D5.ZIP
/
EXTERN
/
TSR.C
< prev
next >
Wrap
Text File
|
1991-04-16
|
4KB
|
180 lines
/*
** TSR.C
**
** This program is a sample TSR that registers itself with HyperPAD. When
** invoked from the DOS prompt, the TSR will unload itself. When invoked from
** within HyperPAD, the TSR will register a callback routine and then exit
** normally. Then, when all pending handlers have executed, HyperPAD will call
** the registered routine.
**
** The trigger keys are LSHIFT+RSHIFT.
**
*/
#include <stdio.h>
#include <stdlib.h>
#include <dos.h>
#include "extern.h"
#include "resident.h"
int (pascal far *callback)(int (_loadds *)());
int (_interrupt *old9)(); /* previous interrupt 9 address */
/*
** comeup()
**
** This routine is the TSR callback. It will be invoked after all pending
** handlers have executed. The address of this routine is passed to the
** registration routine.
**
** The routines called from within this function are documented in the
** PADtalk Reference Guide in Appendix 3 - Writing Extensions. They are
** actually implemented within HyperPAD itself.
**
*/
_loadds comeup()
{
SHAREDPTR pShared;
MSG Msg;
PACKETPTR Screen;
pShared = GetSharedArea();
Screen = pShared -> pVideoModes[0];
HideMouse();
MakeWin(10,10,70,20,78,Screen);
PutStr(12,12,"Hello World",Screen);
ShowMouse();
do {
GetEvent(&Msg);
} while (Msg.Event != EVENT_DOUBLECLICK);
HideMouse();
RemWin();
ShowMouse();
/* don't call this routine anymore */
(*callback)(NULL);
}
/*
** _int9()
**
** This routine gets called when a key is pressed, released, or repeated. It
** keeps track of the left and right shift keys. When both are pressed,
** HyperPAD is notified and passed the address of the routine to call.
**
*/
_interrupt int9()
{
BYTE key;
static int lshift = 0;
static int rshift = 0;
key = inp(0x60);
if (!(key & 0x80)) {
/* a key is pressed */
/* check to see if the key is either the left or right shift key */
if (key == 42) lshift = 1;
else if (key == 54) rshift = 1;
if (lshift && rshift) {
/* both shift keys are pressed, tell HyperPAD about it */
if (callback = hploaded()) {
/* HyperPAD was installed, so pass it my routine */
(*callback)(comeup);
}
else unload(); /* HyperPAD wasn't there, unload the TSR */
}
}
else {
/* a key was released */
key &= 0x7f;
if (key == 42) lshift = 0; /* left shift */
else if (key == 54) rshift = 0; /* right shift */
}
/* chain to the previous interrupt 9 handler */
(*old9)();
}
/*
** take9()
**
** This routine chains into interrupt 9 - the keyboard interrupt.
**
*/
take9()
{
old9 = _dos_getvect(0x09);
_dos_setvect(0x09,int9);
}
/*
** return9()
**
** This routine removes the TSR from the interrupt 9 chain.
**
*/
return9()
{
_dos_setvect(0x09,old9);
}
/*
** reside()
**
** This routine performs the necessary steps to leave me resident.
**
*/
reside()
{
WORD *p;
WORD *EndBlock;
take9();
/* free the environment */
FP_SEG(p) = _psp;
FP_OFF(p) = 0x2c;
_dos_freemem(*p);
/* find the end of program pointer */
FP_SEG(EndBlock) = _psp; /* find psp segment */
FP_OFF(EndBlock) = 2; /* set end of program pointer */
/* terminate and stay resident */
_dos_keep(0,*EndBlock - _psp);
}
/*
** unload()
**
** This routine removes the TSR from memory.
**
*/
unload()
{
return9();
_dos_freemem(_psp);
}
main()
{
reside();
}